How to set inputText to required without affecting output label in Primefaces? - jsf

When I set an inputText to required, the the outputLabel I have associated with the inputText gets an asterisk added to it automatically. How do I prevent the asterisk from appearing?
<p:outputLabel value="Target Species" for="idInputText" />
<p:inputText id="idInputText" required="true" value="#{controller.string}"/>
I am using PrimeFaces 4.0

I would recommend using the plain JSF <h:ouputLabel… />
<h:outputLabel value="Target Species" for="idInputText" />
<p:inputText id="idInputText" required="true" value="#{controller.string}"/>
This removes the asterisk but keeps the label correctly associated with the input element. This is important for accessibility.

Not sure if this also works for 4, but it does for PrimeFaces 5.3: simply add indicateRequired="false". So:
<p:outputLabel value="Target Species"
for="idInputText"
indicateRequired="false"/>
<p:inputText id="idInputText"
required="true"
value="#{controller.string}"/>

Another option is to use css to hide the asterisk:
.ui-outputlabel-rfi { display: none; }
Then the label will still be associated with the input, and you can still use a Label Provider if you like:
http://cagataycivici.wordpress.com/2011/02/11/label-provider-for-jsf-input-components/

indicateRequired="true"
For example:
<p:inputText value="#{bean.firstName}" indicateRequired="true" required="true" requiredMessage="Name is required"/>

<p:outputLabel value="Target Species" for="idInputText" />
<p:inputText id="idInputText" required="true" value="#{controller.string}"/>
In your code ,you're specifically setting that label for inputText and this will have asterisk.
Remove "for" from outputLabel. It should look like :
<p:outputLabel value="Target Species" />
Now, you won't have asterisk .

Related

Invoking a text box and action method for several input text fields?

I'm new to jsf and not sure how to frame the question in a right way. I'm doing a name lookup functionality and my input form is as follows:
Accept input from a text field.(Backed by managed bean and
getters and setters)
Invoke the action using command button.
Display it back on the UI.
I'm not able to paste the entire code because of confidentiality.
<h:form>
<p:outputLabel value="ABC" />
<p:inputText id="a" value="#{mybean.variable}" size="10" />
<p:commandButton value="Check" actionListener="#{mybean.getName()}" update="name">
</p:commandButton>
<p:inputText id="name" value="#{mybean.Value}" />
</h:form>
The above mentioned works fine,However I have 5 input text fields and their corresponding action methods like as follows:
<p:outputLabel value="DEF" />
<p:inputText id="b" value="#{mybean.variable1}" size="10" />
<p:commandButton value="Check" actionListener="#{mybean.getName()}" update="name" >
</p:commandButton>
<p:inputText id="name" value="#{mybean.Value}" />
</h:form>
and so on.
When I put all the text boxes and their corresponding actions,the input is not passed to the backend and the console does not display anything.
Any help appreciated.
Thanks.

Escaped itemLabel for p:selectBooleanCheckbox

I have a question regarding the primefaces component p:selectBooleanCheckbox.
I have following code, which renders a simple boolean checkbox with its label.
<p:selectBooleanCheckbox id="agb" value="#{mobiFormF000001Model.agbChecked}" itemLabel="#{msgs['agb']}">
<f:ajax render="submit" />
</p:selectBooleanCheckbox>
Now my problem is, that in the label i have an URL, which now is escaped and my label looks like this:
Ich bestätige, dass ich die Angaben zum Datenschutz gelesen habe und diese akzeptiere.
Is there a way to get that part rendered as link?
Why don't you simply use <h:outputText> that has the escape property?
<p:selectBooleanCheckbox id="agb" value="#{mobiFormF000001Model.agbChecked}" >
<f:ajax render="submit" />
</p:selectBooleanCheckbox>
<h:outputText escape="false" value="#{msgs['agb']}" />
You can link a p:outputLabel to the checkbox and put any content in its body:
<p:selectBooleanCheckbox value="#{bean.value}"/>
<p:outputLabel for="#previous">
I agree to the terms and conditions
</p:outputLabel>

How to make one field from two required at least with JSF/Primefaces

I'm using primefaces with jsf and i want to make one of two fields required at least. that means that the error message will be displayed if this two fields are empties togheter:
this is a sample of my code:
<h:outputLabel for="srcNumber" value="Originator MSISDN (EXAMPLE 32495959595)" />
<p:inputText id="srcNumber" value="#{cdrMmscRecBean.srcNumber}" label="srcNumber" />
<h:outputLabel for="destNumber" value="Destination MSISDN (EXAMPLE 32495959595)" />
<p:inputText id="destNumber" value="#{cdrMmscRecBean.destNumber} label="destNumber" />
thanks :)
You can implement it this way:
<p:inputText id="srcNumber" value="#{cdrMmscRecBean.srcNumber}" label="srcNumber"
required="#{empty cdrMmscRecBean.destNumber}" requiredMessage="SRC Number Required">
<p:ajax event="change" update="destNumber" />
</p:inputText>
<p:inputText id="destNumber" value="#{cdrMmscRecBean.destNumber}" label="destNumber"
required="#{empty cdrMmscRecBean.srcNumber}" requiredMessage="DEST Number Required">
<p:ajax event="change" update="srcNumber" />
</p:inputText>
For more reference on how to parametrize your validation message:
Parametrized Messages in JSF with Facelets Taglib Functions
If you want to show the validation error use <p:message for="srcNumber" />
and same for test number, get rid of your outputLabels, this will show the validations warnings.
You neeed to add the required="true" flag to your inputTexts as well.
This is primefaces
EDIT
Purpose of the h:outputLabel and its "for" attribute this here shows the outputLabel for using non primefaces to show validatoin messages if this is all your problem was then u just need to add the required="true" validation flag indicators on your input texts

Value is not populated in <p:inputMask> in jsf

when i put attribut mask="" in p:inputMask tag,it populate value properly like this::
<h:outputLabel for="lblPostalCode" value="#{label.postalCode}:" style="font-weight:bold" />
<p:inputMask id="lblPostalCode" style="width: 80px" value="#{certHolderDetail.selectAdd.postalCode}" mask="" />
But when i used default mask for that field like mask="99999-9999" like this
<h:outputLabel for="lblPostalCode" value="#{label.postalCode}:" style="font-weight:bold" />
<p:inputMask id="lblPostalCode" style="width: 80px" value="#{certHolderDetail.selectAdd.postalCode}" mask="99999-9999" />
it does not populate the value......:(
Please look this.
My guess would be that the value (#{certHolderDetail.selectAdd.postalCode}) does not actually conform to the pattern. Eg, perhaps it is a 5 digit address, instead of the expected 5+4?

Dynamically changing the visibility of the JSF components

My requirement is like this: I am having a text input and whenever a value change event occurs, a select many list box has to be populated. If there is no matching records found, then a text input has to appear instead of a select many list box.
<h:column>
<h:selectManyListbox size="3" value="#{hostInfoBean.gateKeeperendPointReference}" rendered="#{hostInfoBean.selectManyRendered}" id="gateKeeperendPointReference">
<f:selectItems value="#{hostInfoBean.gateKeeperendPointReferenceItems}" />
</h:selectManyListbox>
<h:inputText id="gateKeeperendPointReferenceText" size="30" rendered="#{!hostInfoBean.selectManyRendered}">
</h:inputText>
</h:column>
Also I am using a4j for the value change listener,
<a4j:support event="onchange" reRender="hostInfo:gateKeeperendPointReference" focus="GFacPath"
ajaxSingle="true" />
'selectManyRendered' is a boolean value which I am determining in the JAVA bean. The program works only for the default value of the boolean variable. If the boolean value is changed during runtime, then the toggle between the visibility of selectManyListbox and inputText is not working. Please help to fix this. Am i missing something?
regards,
Suresh
If the "rendered" attribute resolves to false, then the component isn't in your tree and can't be found as a "rerender" target. When you have components that are rendered conditionally you want to wrap them in a component that is always available as a target, like so:
<h:inputText value="#{myBean.text}" >
<a4j:support event="onkeyup" reRender="listZone" ajaxSingle="true" />
</h:inputText>
<h:panelGroup id="listZone">
<h:selectManyListbox value="#{myBean.list}" rendered="#{myBean.renderList}" >
<f:selectItems value="#{myBean.listItems}" />
</h:selectManyListbox>
<h:inputText size="30" rendered="#{!myBean.renderList}/>
<h:panelGroup id="listZone">

Resources