What can I do with this scriptlet
<%
ResultRow row = (ResultRow) request.getAttribute(BookAndAuthor.SEARCH_CONTAINER_RESULT_ROW);
Book book = (Book) row.getObject();
%>
If I want to use value="${book.BookId} in this code?
<liferay-ui:icon-menu>
<portlet:actionURL name="deleteBook" var="deleteBookVar">
<portlet:param name="bookId" value="<%=String.valueOf(book.getBookId())%>" />
</portlet:actionURL>
</liferay-ui:icon-menu>
This is a little tricky but I thing it should work.
Use a variable to hold the value of the constant SEARCH_CONTAINER_RESULT_ROW
<c:set var="resultRowConstant" value="<%=BookAndAuthor.SEARCH_CONTAINER_RESULT_ROW%>" />
than to read the attribute you you should be able to use bracket notation to access 'dynamic' properties:
<c:set var="row" value="${[resultRowConstant]}"/> and that will hold the ResultRow object, than you access your book object through
${row.object}
Related
I am trying to render a data table using ajax (BootsFaces) according to the values provided in the form. Unfortunately, desired part does not render. I can see the ajax request is going in the network tab, but it does not do anything (Area does not render and this searchPartialBean.getSearchList() method does not get called). Below is my code snippet. Is there any issue in the way I am doing it ?
<b:tab title="Search">
<h:form>
<b:row>
<b:column mediumScreen="7">
<b:inputText placeholder="Telephone number" label="Telephone number"
value="#{searchPartialBean.telephoneNumber}"/>
<b:inputText placeholder="First name" label="First Name"
value="#{searchPartialBean.firstName}"/>
<b:inputText placeholder="Last name" label="Last Name"
value="#{searchPartialBean.lastName}"/>
<b:commandButton look="primary" id="search-form-submit" value="Search"
update="serach-results-table"/>
</b:column>
<b:column mediumScreen="5">
<b:alert severity="info" title="Info">
This will contain the search help.
</b:alert>
</b:column>
</b:row>
<br />
<b:panel id="serach-results-table">
<b:dataTable rendered="#{searchPartialBean.valuesPresent}" value="#{searchPartialBean.getSearchList()}" var="patient">
<b:dataTableColumn label="Date" value="#{patient.firstName}"/>
</b:dataTable>
</b:panel>
</h:form>
</b:tab>
You've wrapped a form in a tab. Both widgets define a namespace, which, in turn, adds a prefix to the id of each widget within. Probably that's the problem.
My first approach would be to add a colon to indicate you're searching in the inner namespace:
update=":search-results-table"
If that doesn't work, you can use the recursive search expression of BootsFaces:
update="**:search-results-table"
However, my favorite approach is to use a CSS pseudo class like so:
update="#(.search-results-table)"
<b:panel styleClass="search-results-table">
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.
I am using templating and pass some values by to use them in the template:
<ui:repeat var="entry" value="#{showEntriesBean.entries}" id="repeatId">
<ui:include src="/templates/entryTemplate.xhtml">
<ui:param name="prePath" value="/" />
<ui:param name="allowedToSee" value="#{bean.calcRandom(0, 10)}" />
</ui:include>
<br />
</ui:repeat>
I found out, that everytime I use the "allowedToSee" variable in my entryTemplate.xhtml, it recalculates its value.
Is there any way to pass the result of calcRandom in a static way? So it is ONCE calculated (when the allowedToSee value is calculated) and performs like a final number? I don't want it to be calculated everytime #{allowedToSee} is used
If you want the value to be held, you should held it somewhere.
What I would do:
1) Create a List<Integer> property.
2) When the values of the entries properties are set, call a method (preRenderEvent? #PostConstruct?) that introduces in your list as many items as there are in entries.
3) Consult that list using the varStatus attribute of ui:repeat
Little more of less, like:
<ui:repeat var="entry" value="#{showEntriesBean.entries}" id="repeatId" varStatus="status">
<ui:include src="/templates/entryTemplate.xhtml">
<ui:param name="prePath" value="/" />
<ui:param name="allowedToSee" value="#{bean.getPrecalculedRandomAt(status.index)}" />
</ui:include>
<br />
</ui:repeat>
More on the varStatus attribute: http://docs.oracle.com/javaee/6/javaserverfaces/2.0/docs/pdldocs/facelets/ui/repeat.html
i have a template page which has all the code i need for ten pages, where the only diff between the pages is some values
the majority of these have been working fine, however i have an issue with this section of code :
<p>
<p:spinner id="ajaxspinner0-19" value="#{tooltipBean.sectionSave}"
stepFactor = "1" min="0" max="19"
disabled = "#{formBean.number != 1}" >
<p:ajax update="ajaxspinnervalue " process="#this" />
</p:spinner>
</p>
the idea behind this code is it goes to the tooltipBean get the section save value, add this value into here and then for this to get the value from another bean
the value in the tooltipBean is
sectionSave = "#{markingBean.markToEdit.markSectionOne}";
and i use the template in the view pages by:
<f:event listener="#{tooltipBean.setupForPageA}" type="preRenderView" />
<ui:include src="/WEB-INF/templates/commonForm.xhtml"/>
i have it working normally without using the template by using :
<p>
<p:spinner id="ajaxspinner0-19" value="#{markingBean.markToEdit.markSectionOne}"
stepFactor = "1" min="0" max="19"
disabled = "#{formBean.number != 1}" >
<p:ajax update="ajaxspinnervalue " process="#this" />
</p:spinner>
</p>
that code would give me the value 71 in the spinner, however the code from the template displays in the spinner #{markingBean.markToEdit.markSectionOne} which is correct i just need this to run and return 71 rather than showing me the value of the code
does this make sense, sorry if i have written it confusingly i am unsure on how to describe the issue
i think it just not getting intalised at the right time, would it be possible to intatlise the page with the values first and then give it time for that new value to get the data in this case 71 before being viewed by the user
You cannot specify EL from a backing bean like that. The spinner control assumes that it will have both get and set access to whatever is passed in as its value attribute. It won't try to interpret the specified value as EL, which could be quite a dangerous side affect.
Here's how I would approach it. Pass in the value as a parameter to your template:
<ui:include src="templates/commonForm.xhtml">
<ui:param name="spinnerValue" value="#{markingBean.markToEdit.markSectionOne}" />
</ui:include>
Then, reference that parameter in your template:
<p>
<p:spinner id="ajaxspinner0-19" value="#{spinnerValue}"
stepFactor = "1" min="0" max="19"
disabled = "#{formBean.number != 1}" >
<p:ajax update="ajaxspinnervalue " process="#this" />
</p:spinner>
</p>
Is there a way to declare more than one "assignTo" attribute to one a4j:jsFunction? Or can i set more than one value to one "assignTo" attribute of one a4j:jsFunction?
This for example:
<a4j:jsFunction name="newJsFunc" ajaxSingle="true" id="arrJsFunc">
<a4j:actionparam name="param1" assignTo="#{bean.value}" assignTo="#{bean.value}"
actionListener="#{bean.actionListenerMethod}" />
</a4j:jsFunction>
Use a4j:param inside a4j:jsFunction instead of a4j:actionparam. In assignTo you can assign value for only 1 bean property. See description of assignTo attribute in VDL doc:
EL expression for updatable bean property. This property will be updated if the parent command component performs an actionEvent.
You can include as many <a4j:param> tags as you need. See book Practical RichFaces Chapter 3 (Listing 3-20). Pseudocode:
<a4j:jsFunction>
<a4j:param name="param1" assignTo="#{someBean.value1}" />
<a4j:param name="param2" assignTo="#{someBean.value2}" />
<a4j:param name="param3" assignTo="#{someBean.value3}" />
</a4j:jsFunction>