zk Listbox ListCell textbox password getValue - java

hello i have a zul like this
<listcell sclass="textColumn"><textbox type="password" value="*+*+*+*+"/></listcell>
<listcell sclass="textColumn"><textbox type="password" value="*+*+*+*+"/></listcell>
as you can see i am setting the value of textbox value="++++" on records coming from the DB but i have a button set a new record on it using this code
model.add(clazz);
of course after the rendering i have cleaning both inputs values to null.[when adding a new record]
when i try to save the records on DB i am checking in zul the values of the 2 inputs and i getting the right values the user input values but when i get the listBox in Java Code i am getting still "++++" on both inputs this is driving me nuts
here is my code
(Textbox)((Listcell)(item.getChildren().get(5))).getFirstChild()).getValue();
(Textbox)((Listcell)(item.getChildren().get(6))).getFirstChild()).getValue();
both are returning "++++" on other hand the previously added items from DB i can modify and i can see the new values the problem comes when i add a new item set to null my question is
((Textbox)((Listcell)(item.getChildren().get(5))).getFirstChild()).setValue(null);
((Textbox)((Listcell)(item.getChildren().get(6))).getFirstChild()).setValue(null);
if this is not working why i am checking null values on afterRender.
this is the values i am receiving
onAfterRender:start[after set the values to null both empty this is in .zul]
onAfterRender:end
onBeforeSend:start[after the inputs of the user before going to Controller this is in .zul].
qwerty qwerty
onBeforeSend:end
inJava:start[the values i am receiving in the listbox before going to save them in this is in .Java]
*+*+*+*+<--Java-->*+*+*+*+
inJava:end

Why are you using MVC ? You can do this in MVVM very easily See this ZK Listbox may be it will help you to USE MVVM for Item rendered you can check this exampleZK Listbox ItemRendered Example

Related

unable to get the default selected value of drop down from selenium

Scenario1: I have two fields in the screen district and territory. For some user it has default value selected and the drop down is disabled.
PFB code for reference.
<select id="abcd" name="xyz" class="12234" style="ghfhgfhfh">
<option class="hide" value="4541ghj" selected="">valley
none</option>
</select>.
I am trying to get the "valley none" as the output if the drop down is disabled.
Scenario 2: I have two fields in the screen district and territory. For some user it has default value selected and the drop down is enabled.
At this time I want to select the option from the drop down now.
For this I am trying to make a common code.
What I am doing now:-
I am making a select type element and them I am trying to get the default value by getfirstselectedvalue() and then saving it in the webelement and then I am doing .gettext(). to get the option selected.
other wise if the null is returned from thr firstselectvalue() function then I am trying to select the value by visible text.
Error:-
if the default value is selected and the drop down is disbaled The getfirstselectedvalue() function is returning null ,if the element type is select but if I make it as webelement and then doing gettext it gives me the value in the field but this cannot be done if the drop down is senabled as at that time the type to element should be select to select the value from enabled drop down. At both the scenario the class is select for the fields
Please help....
As mentioned by Greg we need the html and the code you tried for better understanding. However, this is the simple logic that you can use.
//get the listBox Element
WebElement list = driver.findElement(By.xpath("//select[#id='abcd']"));
// check if it's disabled
if (!list.isEnabled()) {
// get value from option 1 as listbox is disabled.
System.out.println(list.findElement(By.tagName("option")).getText());
}else {
// select value as listbox is enabled. (Chnage 'Scenario2' with desired list item
list.findElement(By.xpath(".//option[.='scenario2']")).click();
}

To prevent Null value entry in JSP page

I've been working on a simple project. Getting data from JSP using text box, then using the Java in backend to save it in the database. I've defined the fields as NOT NULL in database, but the problem is when I click on submit, the data is saved in database as "", I mean it doesnt take it as NULL and it stored it as BLANK or "". Is there any way to prevent the submit action even if any one field is NULL or without entry? I know I can check it in backend Java, but I've to check every value as NOT NULL if I do by this way. Stopping the Submit action if anyone of the field is NULL is a decent choice.
Try using required="true" for the fields you do not want to allow to be empty. For example:
<h:inputText id="user" styleClass="txtinput" value="#{login.user}" required="true"/>
You cannot control the value being sent unless you use the framework(e.g struts,spring,jsf) specific tags and it has inbuilt validation on the client side.
There is nothing called as null on the form.Everything goes as String.
You have to write client side validations for Blank or "" and check for this value before submission.
If the value is Blank or "" then do not submit.

get text from dynamic table cell to to database

Alright so what I want to do is save text from my table to the database. The table is dynamically generated via a hibernate connection to the db. A sample of the html in the .jsp for the table:
display:column property="ticketId" href="/ossWeb/displayTicketEdit.do" paramId="ticketId" title="Ticket ID"/>
<display:column property="ATCNotes" title="ATC Notes" class="notes" />
<display:column property="issue" title="Issue"/>
<display:column property="status" title="Status"/>
Each property maps directly to a column of a view in the db.
I use this jQuery to allow any cell in the ATC Notes column to be clicked and turn into a text box:
$(".notes").live('click',(
function(){
var text = $(this).text();
$(this).text('');
$('<input type="text" />').appendTo($(this)).val(text).select().blur(
function(){
var newText = $(this).val();
$(this).parent().text(newText).find('input:text').remove();
});
}));
When you click off the cell, the text replaces what was already in the cell. Each row corresponds to a ticketId as can be seen in my first line of the jsp. Now my question is, how do I get that entered text to the db? I have a check box on each row, and for that, I can just assign it a value of "${ATCQueue.ticketId}" but there doesn't seem to be any similar way to differentiate each cell in the ATC Notes column.
I've heard of AJAX being used for something somewhat close to this, but honestly I'm pretty new to this and know next to nothing about AJAX.
I don't think you mandatorily need AJAX for this. You can write an action servlet and submit the form.
Or you can go for native AJAX using XMLHttpRequest/Response. Another way would be to use DWR framework.
1.First thing if you want to save bulk amount of data I i.e; multiple row and multiple column then you need to set a flag(a hidden field or
local storage in html 5) for modified rows.
2.Iterate through th rows of the table and generate xml or json .
3.yes you heard it right the Ajax, now send the data to your code behind through Ajax call.

issues passing dropdown value to java

I have a bunch of select tags in my page where some of them allows the user to use the dropdown and some of them will be disabled at a given time. so I have a select tag in my jsp such as:
<html:select name="myobject" property="myfield" disabled="$(isDisabled ? 'disabled' : '')"/>
I wanted to set as readonly a select tag on my jsp but apparently is not possible so I had to put disable. Since disabled values are not passed back to the application when a user submits the action I created a hidden object of it to pass it as it's suggested everywhere to work around that...
<html:hidden name="myobject" property="myfield" indexed="true"/>
The problem is.. when the form is submited I don't get the new dropdown value selected by the user, I debug into my java code and what I receive is the value that was originally sent to the page instead of what the user picked. It works if I removed the hidden field but if I do so then the disabled selections won't displayed when refreshed cause disabled fields don't pass back the values and i'll receive null at my end... how do I fix this problem?
Thanks,
There may be a duplicate of name or property of the html hidden component.

dynamically update textbox value from database when combobox value is changed

Here is the situation. I have a drop down menu. The option sin this drop down menu are being populated by fetching some values from the database. To do this following is what i have done.. :-
<select name="product_list" onchange="selectProduct(this.value)">
<option value="none">Select one</option>
<%
List<String> options = new ArrayList<String>();
DynamicCombo comboBox = new DynamicCombo();
options = comboBox.generateComboBox();
Collections.sort(options);
int tempVar = 0;
while (tempVar < options.size()) {
out.print("<option value=\"");
out.print(options.get(tempVar));
out.print("\">");
out.print(options.get(tempVar));
out.print("</option>");
tempVar++;
}
%>
</select>
DynamicCombo is a class that has a method called 'generateComboBox()'. This method simply returns an array list containing all the values that are fetched from the database, which is what i need to show in my drop down box in the front end (jsp page). On my jsp page i simply iterate through this list and print it as options appropriately.
This works absolutely fine.
Now i have another text box on my form, say 'textbox1'. Now the requirement is that this text box value should be updated depending on what the user has selected from the above drop down box.
So for example if the user selects 'prod1'(which is a primary key in the backend database table) option from the drop down box, then the corresponding value ( the product name) should be fetched from the database table and should be updated in the textbox named 'textbox1'.
The other thing is this entire thing is contained in a form which is supposed to be finally submitted to the servlet for further processing.
So how can i achieve this.
i figured out the solution to my own problem. It might not be the most elegant way of doing it, but it does the job pretty well.
So as per my requirement, what i exactly wanted to do was.... insert a value (that will be fetched from the database) into a text box on my form depending on what the user chooses from the drop down box that is already present on my form.
To achieve this, i went about and thought if some how i could nest a form withing my main form, it'd solve my issue. But i discovered that nesting of forms is not allowed. So the next option i thought of was to some how submit the same form without the user clicking on the submit button and also handle it appropriately as an 'incomplete' submit (in the sense that the form is still to be submitted manually by the user by clicking on the submit button) on the server.
So i simply made use of the 'onChange' event of a drop down box. I created an additional hidden field on my form.I wrote a simple javascript function that would simply set the value of the hidden field to the string-"partial Submit" and would submit my main form (say named 'form1') as :-
document.getElementById("hidden_id").setAttribute("value","partial submit");
form1.submit;
The function that does the above will be called whenever (and everytime) the onchange event of the drop down box gets fired.
When the user finally clicks on the submit button on the form to submit the finally completed form, then another javascript function is called that simply sets the value of the hidden field on the form to the string, "final submit" and would submit the form as :-
document.getElementById("hidden_id").setAttribute("value","final submit");
form1.submit;
Now on my server, i checked for the value of this hidden field as :-
if(request.getParameter("hidden_id").equals("partial Submit"))
{
// make a database connection, pass the value user selected from the drop down box
// to a prepared statement that does the query for getting the 'productName' from
// the database, collect the returned string in a variable and set a
// request attribute with this returned value. This value can simply be used in the
// jsp to fill in the value part of the textbox1.
}
else
{
if(request.getParameter("hidden_id").equals("final Submit"))
{
// do the rest of the final processing that needs to be done when user finally
// submits the completed form.
}
else
{
// throw an exception to take care of the possibility that the user might send
// in a 3rd value as a value for the hidden field.
}
}
Since you havent provided the code for selectProduct(this.value) , i presume that it submits the jsp page as when you change the value in the drop down.
If that the case in the servelt, set the value that you want to show in jsp in request object
request.setAttribute("valuetodisplay" ,valuetodisplay);
and now in jsp
<input type="text" value ='<%= request.getAttribute("valuetodisplay")%>' />

Categories