This question already has answers here:
Conversion Error setting value for 'null Converter' - Why do I need a Converter in JSF?
(2 answers)
How to populate options of h:selectOneMenu from database?
(5 answers)
Closed 2 years ago.
I have two entities which are in a relationship:
// Produkt
#ManyToOne
private Hersteller hersteller;
// Hersteller
#OneToMany(targetEntity = Produkt.class)
private List<Produkt> produkte;
I have a jsf form to edit a Produkt entity (which works fine yet).
Now i want to change the "Hersteller" of a "Produkt".
<h:selectOneMenu styleClass="form-control" id="hersteller" value="#adminProduktMgmtHandler.produkt.hersteller}">
<f:selectItems value="#{adminProduktMgmtHandler.hersteller}" var="hersteller" itemLabel="#{hersteller.name}" itemValue="#{hersteller}" />
</h:selectOneMenu>
The output is correct, but when i submit it i get the following error:
Conversion Error setting value for 'null Converter'
The generated html:
<select id="kunden-form-register:hersteller" name="kunden-form-register:hersteller" class="form-control" size="1"> <option value="de.hsb.app.gws.model.Hersteller#2169a647">Coca Cola</option>
<option value="de.hsb.app.gws.model.Hersteller#3d9db94c">PepsiCo</option>
</select>
Im a newbie in jee/jsf, but afaik it should work by passing the object correctly right? I don't have to use a id a itemValue to set it?
Solution:
Okay, works by just setting the id as itemValue...
<h:selectOneMenu styleClass="form-control" id="hersteller" value="#{adminProduktMgmtHandler.produkt.hersteller.id}">
<f:selectItems value="#{adminProduktMgmtHandler.hersteller}" var="hersteller" itemLabel="#{hersteller.name}" itemValue="#{hersteller.id}" />
</h:selectOneMenu>
Related
I have an issue to fill property placeholder for JSF passthrough element:
JSF:
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
<!-- ... -->
<h:selectOneMenu value="#{page.selectedCategoryDataKey}" id="mobileFilters" valueChangeListener="#{page.newCategorySelected}" layout="lineDirection" enhanced="true">
<f:selectItem value="#{null}" itemLabel="#{messages.category_all}"/>
<f:selectItems value="#{manager.dataEntryList}" var="categoryEntry" itemValue="#{categoryEntry.key}"
itemLabel="#{categoryEntry.value.categoryName}"
pt:data-track-name="See-#{categoryEntry.key}"/>
<f:ajax execute="#this" render="#form -list"/>
</h:selectOneMenu>
HTML I get
<select id="mobileFilterSelectForm-mobileFilters" name="mobileFilterSelectForm-mobileFilters" size="1" onchange="m.ab(this,event,'valueChange','#this','#form list')"> <option value="" selected="selected">All</option>
<option value="Some" data-track-name="See-">Some</option>
<option value="Most Popular" data-track-name="See-">Most Popular</option>
<option value="New" data-track-name="See-">New</option>
<option value="Instant" data-track-name="See-">Instant</option>
</select>
As you can see data-track-name does not contain value concatenated to See- string, as it is evaluated to itemValue or itemLabel.
Can it be possible that passthrough does not evaluate placeholders as for regular JSF attributes? Any ideas how to get it evaluated?
If you set execute="#this" then none of the input fields will be executed by the JSF framework. Set its value to #parent or #form or list the necessary input field IDs. Render just specify the components to be rendered. Execute specify what postback parameters to be converted, validated, event listeners called and copied to the model.
It should work:
<f:ajax execute="#parent".../>
JSF will evaluate value expressions in the placeholder attributes. However as you've found it's not able to evaluate them when you're using the iteration var inside of selectItems; I tested both cases. It looks like a bug.
This question already has answers here:
How can I pass selected row to commandLink inside dataTable or ui:repeat?
(4 answers)
Closed 6 years ago.
Basically what I have is a list called "mep", I display its values with commandlink and all i want is once you select a link to assign its value to my bean property "selectMep", the display part works pretty well and I'm struggling with the assignment part as I get an error which says that a String (the type of my bean property) cannot be casted to a UIcomponent, here's my code:
<ui:repeat var="mep" value="#{helloBean.mep}" >
<tr>
<td>#{mep}</td>
<h:commandLink value = "#{mep}" action="" binding="#{helloBean.selectMep}"/>
</tr> <br></br>
</ui:repeat>
Any suggestions?
I would suggest to use the action of the commandLink, like this:
<h:commandLink value="#{mep}" action="#{helloBean.selectMep(mep)}" />
And add a new method to your bean:
public void selectMep(String val) {
System.out.println(val);
}
This question already has an answer here:
Specify conditional rendering of element inside <ui:repeat>? The <c:if> does not seem to work
(1 answer)
Closed 7 years ago.
I am trying to use a c:if statement inside a ui:repeat tag.
However U cannot get the value of course.days while inside the if tag. It just always evaluates to empty.
<div id="schedule_wrapper">
<ui:repeat value="#{schedule.courses}" var="course">
<div class="course">
<b>#{course.shortTitle}</b> : #{course.subjectCode} #{course.courseNumber}-#{course.section}<br />
#{course.roomCode} #{course.buildingName} <br />
<c:if test="${not empty course.days}">
#{course.days} : #{course.startTime} - #{course.endTime}
</c:if>
</div>
</ui:repeat>
</div>
Any ideas how I can use the course.days variable inside the if statement?
Or an alternate way to achieve the same thing...
All of the other course.xxxxx value as pulling their values in.
Try to use inside your using a rendered to check your condition.
rendered="#{not empty course.days}" or #{course.days > 0} if days is a Integer
<div id="schedule_wrapper">
<ui:repeat value="#{schedule.courses}" var="course">
<div class="course">
<b>#{course.shortTitle}</b> : #{course.subjectCode} #{course.courseNumber}-#{course.section}<br />
#{course.roomCode} #{course.buildingName} <br />
**<ui:fragment rendered="#{not empty course.days}">
#{course.days} : #{course.startTime} - #{course.endTime}
</ui:fragment>**
</div>
</ui:repeat>
</div>
I found an alternate way to achieve this.
Instead of:
<c:if test="${not empty course.days}">
#{course.days} : #{course.startTime} - #{course.endTime}
</c:if>
I used:
<h:panelGroup rendered="#{not empty course.days}">
#{course.days} : #{course.startTime} - #{course.endTime}
</h:panelGroup>
I am still interested if this is possible with an if statement.
This question already has answers here:
How to make number input area initially empty instead of 0 or 0.00?
(4 answers)
Closed 5 years ago.
I have this primefaces inputText component that links to a double value in my backing bean:
<p:inputText id="valueI"
value="#{productMB.total}">
<f:convertNumber type="number" maxFractionDigits="0" />
</p:inputText>
When the total is 0 the inputText shows a zero. I need to show an empty value because a zero is visually ugly
How can I do that?
Use Double instead of double so that it defaults to null instead of 0.0. Primitives can't be represented as null (and therefore also not render as empty).
Is there any inbuilt number validator tag in JSF that checks whether an input entered in h:inputext field is a number?
The first question was answered. Edited to explain the next problem:
<h:inputText id="maxrecs" value="#{simpleBean.numRecords}" required="false" maxlength="4" >
<f:convertNumber longOnly="true"/>
</h:inputText>
Backing Bean
private long numRecords = null;
If I use String or Integer object in the backing bean , value is not being set. Now when I use primitive int, 0 is being printed on the screen. I would like the screen to be empty.
You can use f:convertNumber (use the integerOnly attribute).
You can get more information here.
You can use:
<f:validateLongRange minimum="20" maximum="1000" />
Where minimum is the smallest number allowed and maximum is the largest.
Look here for more details
JSF Number validation for inputtext
mention f:converterNumber component in between h inputText component and mention the attributes integerOnly and type.
<h:inputText id="textMobileId" label="Mobile" styleClass="controlfont" value="#{UserRegistrationBean.textMobile}">
<f:convertNumber integerOnly="true" type="number" />
</h:inputText>
If you enter abcd in Mobile textbox at the time when you click on commandbutton it automatically shows an error like
Mobile: 'abcd' is not a number.
i8taken solution converts number into long without validation message (at least in my case: JSF2 / global messages per page). For proper validation message you can
1. check value in action method in bean;
or
2. use converter attribute for inputText:
<h:inputText id="maxrecs" value="#{simpleBean.numRecords}" maxlength="4" converter="javax.faces.Integer" />
You can simply use the passthrough, so first add this library
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
and after use this
<h:inputText id="numberId" pt:type="number" />