Requesting for JSON using Volley and serializing - java

I have a JSON file placed in the server which describes one academic week schedule of a class. I have to request for it using Volley. Later I need to serialize the returned JSON object individually and create multiple events for that particular month.
But when I run the application, Volley returns onErrorResponse. When I try doing the same with Retrofit, it worked fine but the output is not as expected.
IT-3-2.json
[{"schedule_of":"IT-3-2","day":"1","from_time":"09:55","to_time":"10:45","subject":"CC","details":"manasa"},
{"schedule_of":"IT-3-2","day":"1","from_time":"10:45","to_time":"11:35","subject":"CC","details":"manasa"},
{"schedule_of":"IT-3-2","day":"1","from_time":"11:35","to_time":"12:25","subject":"WT","details":"asha"},
{"schedule_of":"IT-3-2","day":"1","from_time":"12:25","to_time":"13:15","subject":"WT","details":"asha"},
{"schedule_of":"IT-3-2","day":"1","from_time":"14:15","to_time":"15:05","subject":"ACS lab","details":"gouthami"},
{"schedule_of":"IT-3-2","day":"1","from_time":"15:05","to_time":"15:55","subject":"ACS lab","details":"gouthami"},
{"schedule_of":"IT-3-2","day":"1","from_time":"15:55","to_time":"16:45","subject":"ACS lab","details":"gouthami"},
{"schedule_of":"IT-3-2","day":"2","from_time":"09:55","to_time":"10:45","subject":"IPR","details":"samreen"},
{"schedule_of":"IT-3-2","day":"2","from_time":"10:45","to_time":"11:35","subject":"IPR","details":"samreen"},
{"schedule_of":"IT-3-2","day":"2","from_time":"11:35","to_time":"12:25","subject":"WT","details":"asha"},
{"schedule_of":"IT-3-2","day":"2","from_time":"12:25","to_time":"13:15","subject":"WT","details":"asha"},
{"schedule_of":"IT-3-2","day":"2","from_time":"14:15","to_time":"15:05","subject":"WT lab","details":"rajesh"},
{"schedule_of":"IT-3-2","day":"2","from_time":"15:05","to_time":"15:55","subject":"WT lab","details":"rajesh"},
{"schedule_of":"IT-3-2","day":"2","from_time":"15:55","to_time":"16:45","subject":"WT lab","details":"rajesh"},
{"schedule_of":"IT-3-2","day":"3","from_time":"09:55","to_time":"10:45","subject":"DWDM","details":"shashikanth"},
{"schedule_of":"IT-3-2","day":"3","from_time":"10:45","to_time":"11:35","subject":"DWDM","details":"shashikanth"},{"schedule_of":"IT-3-2","day":"3","from_time":"11:35","to_time":"12:25","subject":"OOAD","details":"madhukar"},{"schedule_of":"IT-3-2","day":"3","from_time":"12:25","to_time":"13:15","subject":"OOAD","details":"madhukar"},{"schedule_of":"IT-3-2","day":"4","from_time":"09:55","to_time":"10:45","subject":"STM","details":"harikrishna"},{"schedule_of":"IT-3-2","day":"4","from_time":"10:45","to_time":"11:35","subject":"STM","details":"harikrishna"},{"schedule_of":"IT-3-2","day":"4","from_time":"11:35","to_time":"12:25","subject":"OOAD","details":"shashikanth"},{"schedule_of":"IT-3-2","day":"4","from_time":"12:25","to_time":"13:15","subject":"OOAD","details":"shashikanth"},{"schedule_of":"IT-3-2","day":"4","from_time":"14:15","to_time":"15:05","subject":"DWDM","details":"shashikanth"},{"schedule_of":"IT-3-2","day":"4","from_time":"15:05","to_time":"15:55","subject":"DWDM","details":"shashikanth"},{"schedule_of":"IT-3-2","day":"5","from_time":"09:55","to_time":"10:45","subject":"IPR","details":"samreen"},{"schedule_of":"IT-3-2","day":"5","from_time":"10:45","to_time":"11:35","subject":"IPR","details":"samreen"},{"schedule_of":"IT-3-2","day":"5","from_time":"11:35","to_time":"12:25","subject":"STM","details":"harikrishna"},{"schedule_of":"IT-3-2","day":"5","from_time":"12:25","to_time":"13:15","subject":"STM","details":"harikrishna"},{"schedule_of":"IT-3-2","day":"5","from_time":"14:15","to_time":"15:05","subject":"CC","details":"manasa"},{"schedule_of":"IT-3-2","day":"5","from_time":"15:05","to_time":"15:55","subject":"CC","details":"manasa"}]
AsynchronousActivity.java
#Override
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
visibleMonth = newMonth;
visibleYear = newYear;
Log.d(TAG, "month changed - "+newMonth);
final String URL = "http://192.168.0.5/practice/schedule/jsons/IT-3-2.json";
// Post params to be sent to the server
HashMap<String, String> params = new HashMap<String, String>();
params.put("token", "AbCdEfGh123456");
JsonObjectRequest req = new JsonObjectRequest(URL,null /*new JSONObject(params)*/,
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Gson gson = new Gson();
VolleyLog.v("Response:%n %s", response);
makeWeeklyEvents((List<WeeklyEvent>) gson.fromJson(response.toString(),WeeklyEvent.class) );
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: ", error.getMessage());
}
});
// add the request object to the queue to be executed
//AppController.getInstance().addToRequestQueue(req);
RequestQueue queue = Volley.newRequestQueue(this);
queue.add(req);
// Return only the events that matches newYear and newMonth.
List<WeekViewEvent> matchedEvents = new ArrayList<WeekViewEvent>();
for (WeekViewEvent event : events) {
if (eventMatches(event, newYear, newMonth)) {
matchedEvents.add(event);
}
}
return matchedEvents;
}
public void makeWeeklyEvents(List<WeeklyEvent> events){
this.events.clear();
for (WeeklyEvent event : events) {
this.events.addAll(event.toWeekViewEvent());
Log.d(TAG, "size of events : "+this.events.size());
}
getWeekView().notifyDatasetChanged();
}
weeklyEvent.java
public class WeeklyEvent {
private static final String TAG = WeeklyEvent.class.getSimpleName();
#Expose
#SerializedName("subject")
private String mName;
#Expose #SerializedName("day")
private int mDay;
#Expose #SerializedName("from_time")
private String mStartTime;
#Expose #SerializedName("to_time")
private String mEndTime;
public String getName() {
return mName;
}
public void setName(String name) {
this.mName = name;
}
public int getDay() {
return mDay;
}
public void setDay(int day) {
this.mDay = day;
}
public String getStartTime() {
return mStartTime;
}
public void setStartTime(String startTime) {
this.mStartTime = startTime;
}
public String getEndTime() {
return mEndTime;
}
public void setEndTime(String endTime) {
this.mEndTime = endTime;
}
#SuppressLint("SimpleDateFormat")
public ArrayList<WeekViewEvent> toWeekViewEvent(){
// Parse time.
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
Date start = new Date();
Date end = new Date();
try {
start = sdf.parse(getStartTime());
} catch (ParseException e) {
e.printStackTrace();
}
try {
end = sdf.parse(getEndTime());
} catch (ParseException e) {
e.printStackTrace();
}
// Initialize start and end time.
Calendar now = Calendar.getInstance();
// Create an week view event.
ArrayList<WeekViewEvent> list = new ArrayList<WeekViewEvent>();
// Create a WeekViewEvent holder
WeekViewEvent weekViewEvent = new WeekViewEvent();
for(int i= getFirstDay(1,AsynchronousActivity.visibleMonth,AsynchronousActivity.visibleYear) - getDay(); i<now.getActualMaximum(Calendar.DAY_OF_MONTH);i+=7 ){
Calendar startTime = (Calendar) now.clone();
startTime.setTimeInMillis(start.getTime());
startTime.set(Calendar.YEAR, AsynchronousActivity.visibleYear);
startTime.set(Calendar.MONTH, AsynchronousActivity.visibleMonth);
startTime.set(Calendar.DAY_OF_MONTH, i);
Calendar endTime = (Calendar) startTime.clone();
endTime.setTimeInMillis(end.getTime());
endTime.set(Calendar.YEAR, AsynchronousActivity.visibleYear);
endTime.set(Calendar.MONTH, AsynchronousActivity.visibleMonth);
endTime.set(Calendar.DAY_OF_MONTH, i);
// Set values into event.
weekViewEvent.setName(getName());
weekViewEvent.setStartTime(startTime);
weekViewEvent.setEndTime(endTime);
weekViewEvent.setColor(Color.GREEN);
Log.d(TAG, "weekly event recieved : "+getName()+", time : "+weekViewEvent.getStartTime().getTimeInMillis() +" - "+weekViewEvent.getEndTime().getTimeInMillis());
// Append WeekViewEvent to the list.
list.add(weekViewEvent);
}
Log.d(TAG, "list is updating "+list.size()+" events.");
return list;
}
public int getFirstDay(int day, int month, int year)
{
Calendar cal = new GregorianCalendar();
cal.set(Calendar.DATE, day);
cal.set(Calendar.MONTH, month);
cal.set(Calendar.YEAR, year);
cal.set(Calendar.DAY_OF_MONTH, 1);
switch (cal.get(Calendar.DAY_OF_WEEK)) {
case Calendar.MONDAY:
return 0;
case Calendar.TUESDAY:
return 1;
case Calendar.WEDNESDAY:
return 2;
case Calendar.THURSDAY:
return 3;
case Calendar.FRIDAY:
return 4;
case Calendar.SATURDAY:
return 5;
case Calendar.SUNDAY:
return 6;
}
return -1;
}
}
Running the application, it returns the follow Volley error: screenshot of logcat
JSON file is accessible when I try the same URL link from the device browser.
When I tried doing the same with Retrofit, it successfully retrieved and processed the JSON but the output was not as expected.
if (!calledNetwork) {
RestAdapter retrofit = new RestAdapter.Builder()
.setEndpoint("http://192.168.0.5")
.build();
MyJsonService service = retrofit.create(MyJsonService.class);
service.listWeekEvents(this);
calledNetwork = true;
MyJsonService.java
public interface MyJsonService {
#GET("/practice/schedule/jsons/IT-3-2.json")
//http://192.168.0.5/practice/schedule/jsons/IT-3-2.json
void listWeekEvents(Callback<List<WeeklyEvent>> weeklyEventsCallback);
}
The functionality is that, I need to duplicate the input event- JsonObject (it contains "day"-day_of_week which represents that event occurs every week on that day) to all that particular day of every week in one month.
for(int i= getFirstDay(1,AsynchronousActivity.visibleMonth,AsynchronousActivity.visibleYear) - getDay(); i<now.getActualMaximum(Calendar.DAY_OF_MONTH);i+=7 ){
Calendar startTime = (Calendar) now.clone();
startTime.setTimeInMillis(start.getTime());
startTime.set(Calendar.YEAR, AsynchronousActivity.visibleYear);
startTime.set(Calendar.MONTH, AsynchronousActivity.visibleMonth);
startTime.set(Calendar.DAY_OF_MONTH, i);
Calendar endTime = (Calendar) startTime.clone();
endTime.setTimeInMillis(end.getTime());
endTime.set(Calendar.YEAR, AsynchronousActivity.visibleYear);
endTime.set(Calendar.MONTH, AsynchronousActivity.visibleMonth);
endTime.set(Calendar.DAY_OF_MONTH, i);
// Set values into event.
weekViewEvent.setName(getName());
weekViewEvent.setStartTime(startTime);
weekViewEvent.setEndTime(endTime);
weekViewEvent.setColor(Color.GREEN);
Log.d(TAG, "weekly event recieved : "+getName()+", time : "+weekViewEvent.getStartTime().getTimeInMillis() +" - "+weekViewEvent.getEndTime().getTimeInMillis());
// Append WeekViewEvent to the list.
list.add(weekViewEvent);
}
When the application is runned (on 14th Feb,2017), the events are shown only from 24th Feb,2017 - 28th Feb,2017. and that to all the duplicate events generated are shown in one day itself.
screenshot of the application showing 26th Feb,2017 while runned with retrofit
I have been using alamkanak/Android-Week-View (link will be posted in answers section if wanted, as more then 2 links can't be posted for now) library to display the events.
Please, help me to solve this problem. Thanks in advance.

Related

How to set a predefined message in lblText.steText()

I want to got the String msg from where Exception is thrown in personAge method so it shows defined error for a person.
How do I get the message from throw new Invalid..("the message");
to the lable?
This is code in my controler
#FXML
void btnRegister(ActionEvent event) {
String name = txtName.getText();
String email = txtEmail.getText();
String phonenr = txtPhonenr.getText();
int year = Integer.parseInt(txtYear.getText());
int month = Integer.parseInt(txtMonth.getText());
int day = Integer.parseInt(txtDay.getText());
boolean validateName = PersonValidator.checkName(name);
boolean validateEmail = PersonValidator.checkEmail(email);
boolean validatePhonenr = PersonValidator.checkPhonenr(phonenr);
try{
PersonAge.personAge(year);
}catch (InvalidAgeException msg){
lblResult.setText(msg);
}
}
And this is where exceptions is thrown :
public class PersonAge {
public static int personAge(int year) throws InvalidAgeException {
Date date = new Date();
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Norway"));
cal.setTime(date);
int thisYear = cal.get(Calendar.YEAR);
int age = thisYear - year;
if(age <=0 || age > 120){
throw new InvalidAgeException("Age is invalid! Try again");
}
return age;
}
}
You just need to call getMessage() on the exception: lblResult.setText(msg.getMessage());

Why I get RuntimeException on AsyncTask?

I'm getting an error while using an AsyncTask. I'm trying get some info from an Excel file using Apache POI. It seems to fail on an Evaluator, used to evaluate cell formulas.
The strange thing is that, when running on the UI thread, it doesn't crash.
Some of the stacktrace is this:
2019-01-28 01:55:08.838 9434-9470/skrb.appprueba E/AndroidRuntime: at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateFormula(WorkbookEvaluator.java:514)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:278)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateReference(WorkbookEvaluator.java:714)
at org.apache.poi.ss.formula.SheetRefEvaluator.getEvalForCell(SheetRefEvaluator.java:48)
at org.apache.poi.ss.formula.SheetRangeEvaluator.getEvalForCell(SheetRangeEvaluator.java:74)
at org.apache.poi.ss.formula.LazyRefEval.getInnerValueEval(LazyRefEval.java:39)
at org.apache.poi.ss.formula.eval.OperandResolver.chooseSingleElementFromRef(OperandResolver.java:179)
at org.apache.poi.ss.formula.eval.OperandResolver.getSingleValue(OperandResolver.java:62)
at org.apache.poi.ss.formula.eval.TwoOperandNumericOperation.singleOperandEvaluate(TwoOperandNumericOperation.java:29)
at org.apache.poi.ss.formula.eval.TwoOperandNumericOperation.evaluate(TwoOperandNumericOperation.java:36)
at org.apache.poi.ss.formula.functions.Fixed2ArgFunction.evaluate(Fixed2ArgFunction.java:33)
at org.apache.poi.ss.formula.OperationEvaluatorFactory.evaluate(OperationEvaluatorFactory.java:119)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateFormula(WorkbookEvaluator.java:514)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:278)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluate(WorkbookEvaluator.java:220)
at org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluateFormulaCellValue(HSSFFormulaEvaluator.java:200)
at org.apache.poi.ss.formula.BaseFormulaEvaluator.evaluate(BaseFormulaEvaluator.java:101)
at reader.ConcreteReader.convertToCustomer(ConcreteReader.java:212)
at reader.ConcreteReader.readCostumersFromSubFolder(ConcreteReader.java:146)
at reader.ConcreteReader.readCostumers(ConcreteReader.java:124)
at reader.ConcreteReader.readCostumersMonth(ConcreteReader.java:79)
at skrb.appprueba.RouteTask.doInBackground(RouteTask.java:63)
at skrb.appprueba.RouteTask.doInBackground(RouteTask.java:27)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
... 4 more
I'm running this on an OnePlus 6 on Android 9.
My AsyncTask can be found here
RouteTask.java(AsyncTask)
public class RouteTask extends AsyncTask<Void, Void, Void> {
private WeakReference<View> viewReference;
public RouteTask(View view) {
super();
viewReference = new WeakReference<>(view);
}
#Override
protected void onPreExecute() {
ProgressBar pb = viewReference.get().findViewById(R.id.progress_recorrido);
pb.setVisibility(View.VISIBLE);
}
#Override
protected void onPostExecute(Void param) {
if (viewReference.get() != null) {
ProgressBar pb = viewReference.get().findViewById(R.id.progress_recorrido);
pb.setVisibility(View.INVISIBLE);
Snackbar snackbarAgregado = Snackbar.make(viewReference.get(), R.string.msg_recorrido_creado, Snackbar.LENGTH_LONG);
snackbarAgregado.show();
}
}
#Override
public Void doInBackground(Void... paramams) {
Date today = Calendar.getInstance().getTime();
Date lastMonth = getMonthBefore(today);
if (lastMonth == null) {
return null;
}
ExcelReader reader = ConcreteReader.getInstance();
Date[] months = new Date[]{lastMonth, today};
Collection<Customer> customers = reader.readCostumersMonth(months,
fileRW.getPath());
Collection<Customer> routeCustomers = new
ConcreteCustomerManager(customers).getRoute();
ExcelWriter writer = ConcreteWriter.getInstance();
writer.WriteRoute(routeCustomers, fileRW.createFileRoute());
return null;
}
private Date getMonthBefore(Date date) {
DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
String dateString = format.format(date);
String[] strings = dateString.split("/");
String resString;
if (Integer.parseInt(strings[1]) == 1) {
strings[1] = "12";
int year = Integer.parseInt(strings[2]) - 1;
strings[2] = String.valueOf(year);
} else {
int month = Integer.parseInt(strings[1]) - 1;
strings[1] = String.valueOf(month);
}
resString = strings[0] + '/' + strings[1] + '/' + strings[2];
try {
return format.parse(resString);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}
EDIT
Also found that running in a Thread doesn't work either. No clues on what is happening yet.
After some time I finally found why this happened. It happens that I was evaluating some formulas on the AsyncTask. This formulas, needed to calculate another formula, and so on. For example, the formula was B41 = B40 + C41*10. Then, B40 = B39 + C40*10, etc. So, this made a big stack of recursive calls, that ended in a stack overflow. This didn't happen (as far as I know) on the UI thread, beacause it has a bigger stack size.

Why updating broadcast variable sample code didn't work?

I want to update broadcast variable every minute. So I use the sample code you give by Aastha in this question.
how can I update a broadcast variable in Spark streaming?
But it didn't work. The function updateAndGet() only works when the streaming application start. When I debug my code , it didn't went into the fuction updateAndGet() twice. So the broadcast variable didn't update every minute.
Why?
Here is my sample code.
public class BroadcastWrapper {
private Broadcast<List<String>> broadcastVar;
private Date lastUpdatedAt = Calendar.getInstance().getTime();
private static BroadcastWrapper obj = new BroadcastWrapper();
private BroadcastWrapper(){}
public static BroadcastWrapper getInstance() {
return obj;
}
public JavaSparkContext getSparkContext(SparkContext sc) {
JavaSparkContext jsc = JavaSparkContext.fromSparkContext(sc);
return jsc;
}
public Broadcast<List<String>> updateAndGet(JavaStreamingContext jsc) {
Date currentDate = Calendar.getInstance().getTime();
long diff = currentDate.getTime()-lastUpdatedAt.getTime();
if (broadcastVar == null || diff > 60000) { // Lets say we want to refresh every 1 min =
// 60000 ms
if (broadcastVar != null)
broadcastVar.unpersist();
lastUpdatedAt = new Date(System.currentTimeMillis());
// Your logic to refreshs
// List<String> data = getRefData();
List<String> data = new ArrayList<String>();
data.add("tang");
data.add("xiao");
data.add(String.valueOf(System.currentTimeMillis()));
broadcastVar = jsc.sparkContext().broadcast(data);
}
return broadcastVar;}}
//Here is the computing code submit to spark streaming.
lines.transform(new Function<JavaRDD<String>, JavaRDD<String>>() {
Broadcast<List<String>> blacklist =
BroadcastWrapper.getInstance().updateAndGet(jsc);
#Override
public JavaRDD<String> call(JavaRDD<String> rdd) {
JavaRDD<String> dd=rdd.filter(new Function<String, Boolean>() {
#Override
public Boolean call(String word) {
if (blacklist.getValue().contains(word)) {
return false;
} else {
return true;
}
}
});
return dd;
}});

Java check two date as String

simply i have two variable as date which they are date as String, for example
"2016-11-30"
when i try to check two variable as this value i get false,
// serverDateTime value is: "2016-11-30"
// Utils.getCurrentDateTime() return: "2016-11-30"
private boolean checkCurrentDate(String serverDateTime) {
if (serverDateTime.equals(Utils.getCurrentDateTime())) {
return true;
} else {
return false;
}
}
public static String getCurrentDateTime() {
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return df.format(c.getTime());
}
Try to use moment.js
var stringDateOne = '2016-11-30';
var stringDateTwo = '2016-11-30';
var momentDateOne = moment(stringDateOne, 'YYYY-MM-DD');
var momentDateTwo = moment(stringDateTwo, 'YYYY-MM-DD');
if(momentDateOne.diff(momentDateTwo, 'days') == 0){
//date equal
}else{
//date not equal
}
hi The code is correct and is returning true for the above entries
public class HelloWorld {
public static void main(String[] args) {
String currDate = "2016-11-30";
HelloWorld hw = new HelloWorld();
System.out.println(hw.checkCurrentDate(currDate));
}
private boolean checkCurrentDate(String serverDateTime) {
if (serverDateTime.equals(HelloWorld.getCurrentDateTime())) {
return true;
} else {
return false;
}
}
public static String getCurrentDateTime() {
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return df.format(c.getTime());
}
}

Setting attribute to the option of DropDownChoice

I have a DropDownChoice:
DropDownChoice dateSpanChoice = new DropDownChoice("dateSpan", new PropertyModel(getModel(), "dateSpan"), dateSpans, new IChoiceRenderer() {
private static final long serialVersionUID = 10105L;
#Override
public String getIdValue(Object object, int index) {
return ((DateSpan) object).getId() + "";
}
#Override
public Object getDisplayValue(Object object) {
DateTime today = new DateTime();
DateTime currentDate = new DateTime(today.getYear(), today.getMonthOfYear(), today.getDayOfMonth(), 0, 0, 0, 0);
DateSpan dateSpan = (DateSpan) object;
DateTime fromDate = dateSpan.getFromDate();
DateTime toDate = dateSpan.getToDate();
boolean currentDateIsEqualOrAfterFromDate = currentDate.isEqual(fromDate) | currentDate.isAfter(fromDate);
boolean currentDateIsEqualOrBeforeToDate = currentDate.isEqual(toDate) | currentDate.isBefore(toDate);
boolean currentDateBelongsToCurrentRange = currentDateIsEqualOrAfterFromDate & currentDateIsEqualOrBeforeToDate;
if (currentDateBelongsToCurrentRange) {
return ((DateSpan) object).getDisplayValue() + " *";
} else {
return ((DateSpan) object).getDisplayValue();
}
}
}) {
private static final long serialVersionUID = 10106L;
protected CharSequence getDefaultChoice(final Object selected) {
CharSequence charSequence = super.getDefaultChoice(selected);
System.out.println("=============================================================");
//System.out.println(charSequence);
//THIS CHARSEQUENCE IS RENRING EMPTY STRING
if(StringUtils.isBlank(charSequence.toString())) {
System.out.println("CHARSEQUENCE IS BLANK");
} else {
System.out.println("CHARSEQUENCE IS NOT BLANK");
}
return charSequence;
}
};
dateSpanChoice.setNullValid(false);
I am trying to add style="background-color: red" to the selected option. So I am overriding getDefaultChoice() but as you can see it is commented in code the CharSequence is empty.
Is there any way to set an attribute to a particular option of DropDownChoice?
Thanks and Regards.
Note: the DateTime is Joda time
You need Select/SelectOption instead of DropDownChoice for more complex uses of element.
Have a look at the behavior package in Wicket.
You can use the AttributeAppender-class for instance.

Categories