I got some troubles with some codes. Now I try to modify/delete personal information , but I enter an invalid value try modify/delete , it's still pop a new window . I dont know how to modify those code for i enter an invalid value , it will not pop a window .
I have other question . When I enter a valid value , the value cant pass to pop window , like I enter a name to go grab id value , the value cant pass to pop window , how can I reslove it . Thank all !
HTML
<h:panelGrid columns="3" cellspacing="20">
<h:outputLabel for="name" value="Modify Name"/> <p:inputText value="#{modify.enName}"/>
<h:commandButton value="Modify System" style="height:35px" onclick="window.open('#{modify.domodify()}','modify',
'width=500,height=400,status=yes,resizable=yes,scrollbars=yes') ; return false;"/>
</h:panelGrid>
Java Code
public String domodify() {
try {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("com.mycompany_SuneCoolingSystem_war_1.0-SNAPSHOTPU");
EmployeeJpaController jpaController = new EmployeeJpaController(null, emf);
EntityManager e = jpaController.getEntityManager();
Query q = e.createNamedQuery("Employee.findByEnName");
q.setParameter("enName", getEnName());
System.out.println(getEnName());
List resultList = q.getResultList();
Employee result = (Employee) resultList.get(0);
id = result.getId();
name = result.getName();
idNumber = result.getIdNumber();
constellation = result.getConstellation();
email = result.getEmail();
enName = result.getEnName();
rego="CRUD/Modify.xhtml";
} catch (Exception ex) {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "No Man", ""));
rego = "index.xhtml";
}
return rego;
}
onclick="window.open('#{modify.domodify()}','modify', 'width=500,height=400,status=yes,resizable=yes,scrollbars=yes')
This code means when clicked, open a new window and perform the action to check what URL is returned. The windows is opened before any logic is executed.
You should perform an ajax call to the modify with f:ajax (or your component library equivalent, if you want) and use onevent to launch the correct javascript when the ajax calls ends in success and returning the expected value.
See JSF 2: How show different ajax status in same input? to see an example of dealing with onevent.
Related
I am having chicken and egg situation:
i have 2 servlets and i want the di object to show through search, not by display servlet
Question:
Is there way I can show the refID in my jsp page even if object is
empty? currently, In my code, i added default query just to fill the "dmsearch" so Jsp don't give
error(SearchDataManagerController.searchDMData(0, 0, 0);).
Or any other solution so my search value should show even display servlet is loaded?
Problem:
On page load, i don't necessarily want to show refId data (servlet 1). if it displays its ok BUT when i click on Search, it should display the data(servlet 2). it displays searched value in textbox but Servlet 1 loads and reset the value back.
Using "Get" in jsp
Code:
<% DataManager di = (DataManager) session.getAttribute("dmsearch"); %>
<input type="text" name="refId" id="refId" value ="<%= di.getiD() %>">
//Servlet display: 1:
DataManager dm;
String buttonClickStatus = request.getParameter("buttonClickStatus");
dm = SearchDataManagerController.searchDMData(0, 0, 0);
session.setAttribute("dmsearch", dm);
//Servlet search: 2:
dm = SearchDataManagerController.searchDMData(driverid, textid, weekid);
session.setAttribute("dmsearch", dm);
please help
Thank you
Solution:
DataManager dm = new DataManager();
int textid=0;
int driverid=0;
int weekid=0;
if(request.getParameter("textid")!=null) {
textid= Integer.parseInt(request.getParameter("textid"));
}
if(request.getParameter("driverid")!=null) {
driverid= Integer.parseInt(request.getParameter("driverid"));
}
if(request.getParameter("weekid")!=null) {
weekid= Integer.parseInt(request.getParameter("weekid"));
}
I'm not sure if this will help you but there is the Expression Language you can read about it, it's so usefull to avoid java code in jsp pages.
You can try this but I'm not sure if this is what you want:
<input type="text" name="refId" id="refId" value ="${ empty di ? 1 : di.getId()}">
Solution:
DataManager dm = new DataManager();
int textid=0;
int driverid=0;
int weekid=0;
if(request.getParameter("textid")!=null) {
textid= Integer.parseInt(request.getParameter("textid"));
}
if(request.getParameter("driverid")!=null) {
driverid= Integer.parseInt(request.getParameter("driverid"));
}
if(request.getParameter("weekid")!=null) {
weekid= Integer.parseInt(request.getParameter("weekid"));
}
I am trying to use SpringMVC to handle a form but now I am stuck and I'm here to ask for your help.
When the user submit the form, my controller returns the jsp result page and the user can check what he filled in. In that result page I have 2 buttons, one to send definitively the form and one to modify it.
Here my problem : when I click on modify all the fields of the form are again empty and I would like to keep the value filled by the user.
My controller :
#Controller
#RequestMapping( "/adhesion" )
public class FormController {
//Send the form
#RequestMapping( method = RequestMethod.GET )
public String getFormulaire( #RequestParam( value = "user", required = false ) T_demande_adhesion User, Map<String, Object> model ) {
System.out.println( "user" + User ); //Null everytime
model.put( "user", User );
System.out.println( "Envoi formulaire !" );
return "formulaireAdhesion";
}
//Handle the form
#RequestMapping( method = RequestMethod.POST )
public String gestionAdhesion( #ModelAttribute( "formAdhesion" ) #Valid T_demande_adhesion user, BindingResult erreurForm, Map<String, Object> model )
throws ServletException, IOException {
final String CHEMIN_DOC_APP = "C:/DocumentsApp/";
// Form JSP page
final String FORMULAIRE_ADHESION = "formulaireAdhesion";
// Result page
final String AFFICHER_RESULT = "afficherResult";
// Objet de validation du formulaire
ValidationDmdAdhesion demandeAdhesion = new ValidationDmdAdhesion();
//Return AFFICHER_RESULT or FORMULAIRE_ADHESION
String resultat = demandeAdhesion.validationUser( user, erreurForm, model, FORMULAIRE_ADHESION, AFFICHER_RESULT, CHEMIN_DOC_APP );
//putting the object to the request
model.put( "user", user );
return resultat;
}
}
In JSP side I added the parameter 'User' in the request :
'
<input type="button" value="Modifier" onclick="document.location.href='<c:url value="adhesion?user=${user}"/>';" class="boutonAdhesion" />
'
But this send me a string and the url is :
/adhesion?user=com.user.entities.T_demande_adhesion#1dfe8158
When the user clicks on modifiy button (which is in the result page), I would like to get this object #ModelAttribute( "formAdhesion" ) #Valid T_demande_adhesion user on the GET request to fill in the form, in purpose to avoid the user to put again the same informations.
Any help ?
An extract from the form :
<label for="nom">Nom <span class="requis">*</span></label><input type="text" id="nom" name="identite.nom" value="<c:out value ="${user.identite.nom}"/>" size="35" maxlength="30" />
<spring-ext:errors path="identite.nom" class="erreur" firstErrorOnly="true"/>
It's here : value="<c:out value ="${user.identite.nom}"/> that I want to get the value of nom.
Sorry for the English.
Frenchy.
When I click on modify all the fields of the form are again empty and
I would like to keep the value filled by the user
Because the form data is already available on the page at client side, there is no meaning of submitting the form again to the server & show the same data, which is an unnecessary round trip from the client to the server i.e.,
To keep the data on the form, do NOT to submit the form to the server/controller itself.
How can I check the validation of the information filled in without
submit the form? How can I display them in my result page?
There is no need to validate the data that the user is anyhow going to modify. So, the validation of the form will be done only after the user completes the modifications and clicks on Submit. Once the validations are successful/failed, your can show the result on the results page.
In this case, I didn't find another way than using #SessionAttributes. In this point off my application I didn't to use a session but it seems that there isn't another way.
I have a <h:commandButton> on my page connected with action in my bean. It work just fine, but I wanted to add confirmation message. When I used:
<h:commandButton onclick="confirm('Are you sure?')">
it alco works just fine. But when I try to get string from bean, by making it looks like this:
<h:commandButton onclick="confirm('#{bean.confirmQ}')"> it doesn't display this string. In getter for this string I invoke method to take some info from DB, and I format it then I return it. When I use this approach nothing is shown, not even empty box, and page looks like just refreshing.
Here is code from bean:
private String confirmQ;
public String getConfirmQ() {
WycenioneAuta wa = getWycenioneAuto();
String question = "are you sure \n" + wa.getName + "?";
confirmQ = question;
return confirmQ;
}
public void setConfirmQ(String confirmQ) {
this.confirmQ = confirmQ;
}
Escape the line by writing String question = "are you sure \\n" + wa.getName + "?";
If your String variable is confirmQ , then the right EL pointing to that variable is #{bean.confirmQ} and not #{bean.confirm} as you've written.
In complement to ஜன்'s Answer:
At least for Firefox , I should had a return in the Javascript code, otherwise the cancel does not work:
<h:commandButton onclick="return confirm('Are you sure?')" ... />
I am just facing the issue at open new browser at "each click event previous opened stay that". i want that.
Look i want to open window browser at click event... it opens fine.
But i want at each click it opens new browser. how can i do that?
it always override that new window. i want always open a new window.
i used:
function Validation(){
var i=0;
if(document.netsim.emulatorNo.value=="")
{
alert ( "Please Fiil Emulator Number" );
netsim.emulatorNo.focus();
i=1;
}else {
var emu = document.netsim.emulatorNo.value;
var serverUrl = document.netsim.Apply.value;
window.open('http://localhost:8080/SMSSimulator/NewEmulator.jsp?emulator='+emu+'&ServerUrl='+serverUrl,'mywindow','width=400,height=350');
}
if(i==1)
return false;
}
suggest me to find out my answer.
Thanks in advance.
window.open(url, unique_title, features)
If you want to open it always on the new window use a unique window title everytime, else it will keep on opening on the same window.
Example sample html and popup opens fine in new window always -
<html>
<script>
var counter = 0;
function openWindow(){
window.open('http://www.google.com','mywindow'+counter,'width=400,height=350');
counter++;
}
</script>
<body>
<input type="button" value="button" id="button" onclick="openWindow()" />
</body>
</html>
you need to give different window names to each window. so, 'mywindow' needs to be changed. try something like;
var counter = 0;
function Validation(){
var i=0;
if(document.netsim.emulatorNo.value=="")
{
alert ( "Please Fiil Emulator Number" );
netsim.emulatorNo.focus();
i=1;
}else {
var emu = document.netsim.emulatorNo.value;
var serverUrl = document.netsim.Apply.value;
window.open('http://localhost:8080/SMSSimulator/NewEmulator.jsp?emulator='+emu+'&ServerUrl='+serverUrl,'mywindow'+counter,'width=400,height=350');
counter++;
}
if(i==1)
return false;
}
Here you open the new window in a specific place called 'mywindow'
window.open('http://localhost:8080/SMSSimulator/NewEmulator.jsp?emulator='+emu+'&ServerUrl='+serverUrl,'mywindow','width=400,height=350');
you can change it to blank or "_blank" and it will open it in a new window:
window.open('http://localhost:8080/SMSSimulator/NewEmulator.jsp?emulator='+emu+'&ServerUrl='+serverUrl,'','width=400,height=350');
there is no need to naming it unless you have a javascript that reference the window
If I have a simple button:
<ice:panelGroup>
<ice:commandButton value="foobar"
action="#{fileManager.openNoFlashVisiblePopup}" />
</ice:panelGroup>
Is it possible to trigger the action openNoFlashVisiblePopup using just javascript? I know that there IceFaces has a JavaScript bridge but I don't know see a simple way to do just this.
i need to do this because I have a chunk of JavaScript that detects Flash and I need to show a IceFaces popup.
One way is to get the button element by ID and call its click() function.
document.getElementById('clientId').click();
You only need to give the form and button a fixed id so that you can use the generated HTML ID as clientId in Javascript code.
I know I'm a little late in seeing this, but the correct way to handle this (minus perhaps the overly exhuberant error checking) is:
// There's a <div> that looks like: <div class="portletfaces-bridge-body" id="A8660">.
// We'll find it and pull out the value of the ID to build elementId like: A8660:wtfForm:editeventparent
var div = null;
var divCollection = document.getElementsByTagName("div");
for (var i=0; i<divCollection.length; i++) {
if(divCollection[i].getAttribute("class") == "portletfaces-bridge-body") {
div = divCollection[i];
break;
}
}
if (div == null){
alert("could not find div portletfaces-bridge-body.");
return;
}
// Pull the id out of divInnerText.
var id = div.getAttribute("id");
if (id == null){
alert("id was null");
}
// prepare initializes fields to null so rendered cannot begin until both itemId and parentId are set.
var prepare = document.getElementById(id + ":wtfForm:editeventprepare");
if (prepare == null){
alert("editeventprepare element was not found.");
return;
}
prepare.click();