I have created web-application using JSF 2.0 & JSP and facing some weird problem.
I have page in JSF where I have included JSP page. code are as below.
<o:resourceInclude path="detailedReports.jsp" />
Where o is omnifaces. xmlns:o="http://omnifaces.org/ui"
Now in JSP (detailedReports.jsp) I have code as below.
<h:form id="myForm" prependId="false">
<h:commandLink value="Take Me To Some Page" action="#{PersonalInformationDataBean.moveToApplicantRegisterPage()}" />
</h:form>
moveToApplicantRegisterPage() have below code
public String moveToApplicantRegisterPage() {
editedData = 1;
return takeMeToAnotherPage("registerForPatentss");
}
When I click on Take Me To Some Page link, I get directed to detailedReports.jsp and not to registerForPatentss.xhtml.
Any reason why this is happening? What should I do to get redirected to registerForPatentss.xhtml.
Note: While redirecting to registerForPatentss.xhtml, I also need to set the data of int editedData to 1.
It might be a rendering problem related to mixing two different view technologies (JSP and facelets).
I don't think there is any solution. So what I did is, take JSP in JSF i.e. I re-wrote JSP content in JSF Format. So now I don't have any JSP page.
All is working perfectly!!!
Related
I am developing an application where I have to show data from the database based on User Input (let's say field empid for employee id and I show some information from database based on this input). I am using JSF, PrimeFace and Hibernate.
Now I have the index.xhtml page where I am taking input the empid. After that, I have to redirect to another page page2.xhtml.
Here is a snippet from index.xhtml:
<h:form>
<p>Employee ID:
<p:inputText value="#{userBean.newuser.empid}" required="true"/></p>
</h:form>
<br />
<h:form>
<p:commandButton action="page2?faces-redirect=true" value="Enter" />
</h:form>
But after re-directing to page2.xhtml, the empid input from index.xhtml page is lost. I tried to read a few posts on this but was not able to understand. Please help. I am sorry if it is a repeated question.
I assume that viewscopes of managed bean in which you are insterested in are #RequestScope ? You could specify more wide view scope for a managed bean, so it won't be destroyed after each request. However #RequestScope is really good when want to minimize session scope bloat. To stay with this session scope you could use flash object which was introduced with JSF 2.0. Thanks to this object you can transfer data between requests. You could put following code snippet :
ExternalContext.getFlash().put("empid", newuser.getEmpid);
in your userBean. After redirect you could retrieve that value on jsf page in the following way :
#{flash.empid}
Or in your managed bean :
ExternalContext.getFlash().get("empid");
More about flash with example can be found in this post or in JSF 2 Flash documentation
I recently upgraded Spring framework from 3.1.2 to 4.1.1. Also upgraded to Tomcat 8 and Java 8. I am also using Tiles 2.2.2.
My web page loads fine using Spring 4 and problem comes when I do a form submission. The URL request changes and leaves out the webapp name.
For e.g., when I do a form submission,
the URL that is expected is supposed to be http://xx.xx.xx.xx/webappname/createuser/submit.
But the URL changes to http://xx.xx.xx.xx/createuser/submit. And thus, throws a "Requested resource is not available " error.
I did not have this problem when I was using Spring 3.1.2, Tomcat 7, Java 7.
May I know what I am missing?
Thank you,
Whiskers
EDIT :
My jsp view goes like
<form:form method="post" action = "/createuser/submit" commandName = "createForm" >
.....
< /form>
Prepend your hyperlinks with:
${pageContext.request.contextPath}
See the accepted answer here
Your action URL is start with root change your action URL to
action = "createuser/submit"
Or used <c:url ... /> tag to create URL and give it to action as shown below
<c:url value="createuser/submit" var="myActionUrl" />
<form:form action="${myActionUrl}" .... >
May this will help you.
We are currently converting a Spring mvc/jsp app into a jsf app.
Previously we could import the content of a JSP segment file into a text area like this
<textarea id="sectionSixPointOne" name="sectionSixPointOne">
<jsp:include page="sect_six_point_one.jspf"/>
</textarea>
Magically the content of the jsp appeared into the content of the text area.
We are trying to do the same with JSF, but I am about ready to shoot myself in the face.
We've tried
<h:inputTextarea id="sectionSixPointOne">
<ui:include src="section_six_sect_one.xhtml"/>
</h:inputTextarea>
But it includes the content after the textarea not inside it.
I have tried to include the content of as the value parameter of h:inputTextarea but the compiler gets it's knickers in a knot about the syntax/quotes/anglebrackets etc.
<h:inputTextarea id="sectionSixPointOne" value=<ui:include src="section_six_sect_one.xhtml"/>
</h:inputTextarea>
I would much rather include the content directly in the jsf pages rather than mucking about loading it into a backing bean.
Anyone got any ideas can what I want to do be done with jsf (apologies for any idiocy I am a total JSF newb?
Just put the <h:inputTextarea id="sectionSixPointOne"> with it's value to include in the file you want to include.
That way you don't need to insert it in some component, you just extracted the whole thing into its own file.
So you code looks like:
<ui:include src="section_six_sect_one.xhtml"/>
and in section_six_sect_one.xhtml":
<ui:composition xmlns=... >
<h:inputTextarea id="sectionSixPointOne" value="yourIncludedText"/>
...
I'm creating some pages for a web application, I currently have some pages with a brief description of a company and a link to allow them to log in to access more information. When the user logs in, they should be redirected to the more detailed version of the page.
In order to do this, when the user clicks on the log in link, I save the company name (as it is used in the url) to the session and access it when the user is logging in to figure out where to redirect them to.
This works fine but the only problem is these pages are using simple file name controllers and I don't want to implement controllers for them just so I can set this attribute. I've found a fix by using scriptlets in my jsp:
<a href="<c:url value='/login.jsp' />"
onclick="<% session.setAttribute( "partner", "companyName" ); %>"
>
Click here to log in
</a>
Now after some reading on SO and other resources I know that use of these scriptlets is highly discouraged, but I'm at a loss as to how to fix this problem without having to implement a controller to handle this simple problem. Any suggestions would be greatly appreciated.
use jstl
<c:set var="partner" value="companyName" scope="session" />
I'm starting building web apps in Spring 3 (and in J2EE) in general.
Looking at the petclinic example I've seen that the programmer creates many JSP pieces, like header, includes, footer and then stitches them together using static inclusion. Anyway what I'd like is that I may have a base page, like Base.jsp and be able to include things like this:
<body>
<jsp:include page="${subpage}"></jsp:include>
</body>
the reason is that I'd like a main page, then being able to put in the ModelAndView returned by the controller which parts of the pages display in each situation (with the data attached to it). This works, but it gives no errors in case ${subpage} is not found, the jsp name is wrong or missing. I'd like more error checking...
Is this the best and recommended way to do this? And if this seems a good idea for what I've in mind, what's the correct way of doing it?
You might want to use Apache Tiles 2 integration for managing your JSP files. Spring has good integration support Apache Tiles. It also shows if there's an error in your page. I've put an example of it at http://krams915.blogspot.com/2010/12/spring-mvc-3-tiles-2-integration.html
It appears you have additional quotes in your subpage. Get rid of them. For example:
<c:set var="subpage" value="/jsp/index.jsp" />
If you have to set it in a controller or servlet - just use request.setAttribute("subpage", "/jsp/index.jsp")
For error checking you can use:
<c:catch var="myException">
<c:import url="${subpage}" />
</c:catch>
and later you can check it with:
<c:if test="${myException != null}">
...
</c:if>
Take a look at Sitemesh (http://www.opensymphony.com/sitemesh). It is a servlet filter-based page layout system that is easy to use. I have done a number of projects using it with Spring MVC and it worked very well.